/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddGuestDialog.java
 *
 * Created on Mar 6, 2010, 6:53:15 PM
 */
package arrival;

import common.SubmitCompanyDialog;
import dbhandler.*;
import common.ImagePanel;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.BorderFactory;

/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class AddGuestDialog extends javax.swing.JDialog {

    private Guest guest;
    private Company company;

    /**
     * Creates new form AddGuestDialog
     * @param parent
     * @param modal
     */
    public AddGuestDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        guest = new Guest();
        initComponents();
        renderData();
    }

    /**
     *
     * @return
     */
    public Guest returnGuest() {
        setVisible(true);
        return guest;
    }

    private void renderData() {
        ArrayList<Country> countryList = new Country().getCountries();
        for (int i = 0; i < countryList.size(); i++) {
            countryBox.addItem(countryList.get(i));
        }

        ArrayList<Prefix> prefixList = new Prefix().getPrefixes();
        for (int i = 0; i < prefixList.size(); i++) {
            prefixBox.addItem(prefixList.get(i));
        }
    }

    private void setGuest() {
        guest.setPrefix((Prefix) prefixBox.getSelectedItem());
        guest.setFirstName(fNameFld.getText() + "");
        guest.setMiddleName(mNameFld.getText() + "");
        guest.setLastName(lNameFld.getText() + "");
        guest.setPassportNo(passportFld.getText() + "");
        guest.setPhone1No(phone1Fld.getText());
        guest.setPhone2No(phone2Fld.getText());
        guest.setEmail(renderEmail());
        guest.setLastRoom(null);
        if (isBusinessChk.isSelected()) {
            guest.setCompany(company);
        }

        // Country
        Country country = (Country) countryBox.getSelectedItem();

        // City
        String tempCity = cityFld.getText();
        String tempCity1 = tempCity.substring(0, 1).toUpperCase();
        String tempCity2 = tempCity.substring(1, tempCity.length()).toLowerCase();
        String cityName = tempCity1 + tempCity2;

        City city = new City();
        boolean cityIsFound = false;
        ArrayList<City> cities = city.getCities();
        for (int i = 0; i < cities.size(); i++) {
            if (cities.get(i).getZip().equals(country.getCountryCode() + zipFld.getText())) {
                city = new City(country.getCountryCode() + zipFld.getText());
                cityIsFound = true;
            }
        }
        if (!cityIsFound) {
            city = new City();
            city.setName(cityName);
            city.setZip(country.getCountryCode() + zipFld.getText());
            city.insert();
            city = new City(country.getCountryCode() + zipFld.getText());
        }

        // Address
        Address address = new Address();
        boolean addressIsFound = false;
        ArrayList<Address> addresses = address.getAddresses();
        for (int i = 0; i < addresses.size(); i++){
            if (addresses.get(i).toString().equals(streetNameFld.getText() + " " + streetNoFld.getText() + " " + city.getZip() + " " + stateFld.getText())){
                address = new Address(addresses.get(i).getAddressNo());
                addressIsFound = true;

            }
            System.out.println(streetNameFld.getText() + " " + streetNoFld.getText() + " " + city.getZip() + " " + stateFld.getText());
        }
        if (!addressIsFound){
            address.setState(stateFld.getText() + "");
            address.setStreetName(streetNameFld.getText() + "");
            address.setStreetNo(streetNoFld.getText() + "");
            address.setCity(city);
            address.setCountry(country);
            address.insert();
        }

        guest.setAddress(address);
        guest.insert();
        System.out.println(address.getAddressNo());
    }

    private String renderEmail() {
        String email = emailNameFld.getText() + "@" + emailDomainFld.getText() + "." + emailExtFld.getText();
        return email;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        infoPnl = new javax.swing.JPanel();
        prefixBox = new javax.swing.JComboBox();
        fNameLbl = new javax.swing.JLabel();
        fNameFld = new javax.swing.JTextField();
        mNameLbl = new javax.swing.JLabel();
        mNameFld = new javax.swing.JTextField();
        lNameLbl = new javax.swing.JLabel();
        lNameFld = new javax.swing.JTextField();
        emailLbl = new javax.swing.JLabel();
        emailNameFld = new javax.swing.JTextField();
        atLbl = new javax.swing.JLabel();
        emailDomainFld = new javax.swing.JTextField();
        dotLbl = new javax.swing.JLabel();
        emailExtFld = new javax.swing.JTextField();
        passportLbl = new javax.swing.JLabel();
        isBusinessChk = new javax.swing.JCheckBox();
        passportFld = new javax.swing.JFormattedTextField();
        addressPnl = new javax.swing.JPanel();
        streetNameLbl = new javax.swing.JLabel();
        streetNameFld = new javax.swing.JTextField();
        streetNoLbl = new javax.swing.JLabel();
        streetNoFld = new javax.swing.JTextField();
        zipLbl = new javax.swing.JLabel();
        stateLbl = new javax.swing.JLabel();
        stateFld = new javax.swing.JTextField();
        cityLbl = new javax.swing.JLabel();
        cityFld = new javax.swing.JTextField();
        countryLbl = new javax.swing.JLabel();
        phone1Lbl = new javax.swing.JLabel();
        phone2Lbl = new javax.swing.JLabel();
        phone1Fld = new javax.swing.JFormattedTextField();
        phone2Fld = new javax.swing.JFormattedTextField();
        zipFld = new javax.swing.JFormattedTextField();
        countryBox = new javax.swing.JComboBox();
        logoPnl = new javax.swing.JPanel();
        saveBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Hotel Lazy BMS - Add Guest");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        infoPnl.setBackground(new java.awt.Color(255, 255, 255));
        infoPnl.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "General Info", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 1, 13))); // NOI18N

        fNameLbl.setFont(fNameLbl.getFont());
        fNameLbl.setText("First name");

        fNameFld.setFont(fNameFld.getFont());

        mNameLbl.setFont(mNameLbl.getFont());
        mNameLbl.setText("Middle name");

        mNameFld.setFont(mNameFld.getFont());

        lNameLbl.setFont(lNameLbl.getFont());
        lNameLbl.setText("Last name(s)");

        lNameFld.setFont(lNameFld.getFont());

        emailLbl.setFont(emailLbl.getFont());
        emailLbl.setText("Email");

        emailNameFld.setFont(emailNameFld.getFont());

        atLbl.setFont(atLbl.getFont());
        atLbl.setText("@");

        emailDomainFld.setFont(emailDomainFld.getFont());

        dotLbl.setFont(dotLbl.getFont());
        dotLbl.setText(".");

        emailExtFld.setFont(emailExtFld.getFont());

        passportLbl.setFont(passportLbl.getFont());
        passportLbl.setText("Passport No.");

        isBusinessChk.setBackground(new java.awt.Color(255, 255, 255));
        isBusinessChk.setFont(isBusinessChk.getFont());
        isBusinessChk.setText("Business Guest");
        isBusinessChk.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        isBusinessChk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                isBusinessChkActionPerformed(evt);
            }
        });

        passportFld.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#"))));

        javax.swing.GroupLayout infoPnlLayout = new javax.swing.GroupLayout(infoPnl);
        infoPnl.setLayout(infoPnlLayout);
        infoPnlLayout.setHorizontalGroup(
            infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(passportLbl)
                    .addComponent(emailLbl)
                    .addComponent(lNameLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(prefixBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(infoPnlLayout.createSequentialGroup()
                        .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(infoPnlLayout.createSequentialGroup()
                                .addComponent(fNameLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(fNameFld, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mNameLbl))
                            .addGroup(infoPnlLayout.createSequentialGroup()
                                .addComponent(passportFld, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(infoPnlLayout.createSequentialGroup()
                                .addGap(183, 183, 183)
                                .addComponent(isBusinessChk))
                            .addGroup(infoPnlLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(infoPnlLayout.createSequentialGroup()
                        .addComponent(emailNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(atLbl)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(emailDomainFld, javax.swing.GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dotLbl)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(emailExtFld, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lNameFld, javax.swing.GroupLayout.DEFAULT_SIZE, 890, Short.MAX_VALUE))
                .addContainerGap())
        );
        infoPnlLayout.setVerticalGroup(
            infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoPnlLayout.createSequentialGroup()
                .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(mNameLbl)
                    .addComponent(prefixBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fNameLbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lNameLbl)
                    .addComponent(lNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(emailLbl)
                    .addComponent(emailNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(emailDomainFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(emailExtFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(atLbl)
                    .addComponent(dotLbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(infoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passportLbl)
                    .addComponent(isBusinessChk)
                    .addComponent(passportFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        addressPnl.setBackground(new java.awt.Color(255, 255, 255));
        addressPnl.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Address", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 1, 13))); // NOI18N

        streetNameLbl.setText("Street");

        streetNoLbl.setText("No.");

        zipLbl.setText("Zip");

        stateLbl.setText("State");

        cityLbl.setText("City");

        countryLbl.setText("Country");

        phone1Lbl.setText("Phone No. 1:");

        phone2Lbl.setText("Phone No. 2:");

        phone1Fld.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#"))));

        phone2Fld.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#"))));

        zipFld.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#"))));

        javax.swing.GroupLayout addressPnlLayout = new javax.swing.GroupLayout(addressPnl);
        addressPnl.setLayout(addressPnlLayout);
        addressPnlLayout.setHorizontalGroup(
            addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addressPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(zipLbl)
                    .addComponent(streetNameLbl)
                    .addComponent(countryLbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(addressPnlLayout.createSequentialGroup()
                        .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(addressPnlLayout.createSequentialGroup()
                                .addComponent(streetNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(streetNoLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(streetNoFld, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(addressPnlLayout.createSequentialGroup()
                                .addComponent(zipFld, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(stateLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(stateFld, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cityLbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cityFld, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, addressPnlLayout.createSequentialGroup()
                                .addComponent(phone1Lbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(phone1Fld, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, addressPnlLayout.createSequentialGroup()
                                .addComponent(phone2Lbl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(phone2Fld, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE))))
                    .addComponent(countryBox, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        addressPnlLayout.setVerticalGroup(
            addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addressPnlLayout.createSequentialGroup()
                .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(streetNameLbl)
                    .addComponent(streetNameFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(streetNoLbl)
                    .addComponent(streetNoFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(phone1Lbl)
                    .addComponent(phone1Fld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(zipLbl)
                    .addComponent(phone2Lbl)
                    .addComponent(phone2Fld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zipFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(stateLbl)
                    .addComponent(stateFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cityLbl)
                    .addComponent(cityFld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addressPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(countryLbl)
                    .addComponent(countryBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        logoPnl.setBackground(new java.awt.Color(211, 211, 211));
        logoPnl.setMinimumSize(new java.awt.Dimension(100, 50));
        logoPnl.setPreferredSize(new java.awt.Dimension(100, 50));

        javax.swing.GroupLayout logoPnlLayout = new javax.swing.GroupLayout(logoPnl);
        logoPnl.setLayout(logoPnlLayout);
        logoPnlLayout.setHorizontalGroup(
            logoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        logoPnlLayout.setVerticalGroup(
            logoPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );

        saveBtn.setText("Save");
        saveBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveBtnActionPerformed(evt);
            }
        });

        cancelBtn.setText("Cancel");
        cancelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(cancelBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveBtn))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(addressPnl, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(infoPnl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(logoPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelBtn, saveBtn});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(logoPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(infoPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(addressPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cancelBtn))
                .addContainerGap())
        );

        logoPnl.add(new ImagePanel("logo.png"));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
        dispose();
    }//GEN-LAST:event_cancelBtnActionPerformed

    private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed
        fNameFld.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        lNameFld.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        streetNameFld.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        streetNoFld.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        zipFld.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        cityFld.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        phone1Fld.setBorder(BorderFactory.createLineBorder(Color.GRAY));


        if (fNameFld.getText().equalsIgnoreCase("")) {
            fNameFld.setBorder(BorderFactory.createLineBorder(Color.RED));
        } else {
            if (lNameFld.getText().equalsIgnoreCase("")) {
                lNameFld.setBorder(BorderFactory.createLineBorder(Color.RED));
            } else {
                if (streetNameFld.getText().equalsIgnoreCase("")) {
                    streetNameFld.setBorder(BorderFactory.createLineBorder(Color.RED));
                } else {
                    if (streetNoFld.getText().equalsIgnoreCase("")) {
                        streetNoFld.setBorder(BorderFactory.createLineBorder(Color.RED));
                    } else {
                        if (zipFld.getText().equalsIgnoreCase("")) {
                            zipFld.setBorder(BorderFactory.createLineBorder(Color.RED));
                        } else {
                            if (cityFld.getText().equalsIgnoreCase("")) {
                                cityFld.setBorder(BorderFactory.createLineBorder(Color.RED));
                            } else {
                                if (phone1Fld.getText().equalsIgnoreCase("")) {
                                    phone1Fld.setBorder(BorderFactory.createLineBorder(Color.RED));
                                } else {
                                    setGuest();
                                    dispose();
                                }
                            }
                        }
                    }
                }
            }
        }
    }//GEN-LAST:event_saveBtnActionPerformed

    private void isBusinessChkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_isBusinessChkActionPerformed
        if (isBusinessChk.isSelected()) {
            // BusinessGuest businessGuest = new BusinessGuest(guest.getGuestNo());
            company = new SubmitCompanyDialog(null, true).returnCompany();
            if (company != null) {
                // businessGuest.setCompany(company);
                guest.setBusinessGuest(true);
            } else {
                isBusinessChk.setSelected(false);
                guest.setBusinessGuest(false);
            }
        }
}//GEN-LAST:event_isBusinessChkActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                AddGuestDialog dialog = new AddGuestDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel addressPnl;
    private javax.swing.JLabel atLbl;
    private javax.swing.JButton cancelBtn;
    private javax.swing.JTextField cityFld;
    private javax.swing.JLabel cityLbl;
    private javax.swing.JComboBox countryBox;
    private javax.swing.JLabel countryLbl;
    private javax.swing.JLabel dotLbl;
    private javax.swing.JTextField emailDomainFld;
    private javax.swing.JTextField emailExtFld;
    private javax.swing.JLabel emailLbl;
    private javax.swing.JTextField emailNameFld;
    private javax.swing.JTextField fNameFld;
    private javax.swing.JLabel fNameLbl;
    private javax.swing.JPanel infoPnl;
    private javax.swing.JCheckBox isBusinessChk;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField lNameFld;
    private javax.swing.JLabel lNameLbl;
    private javax.swing.JPanel logoPnl;
    private javax.swing.JTextField mNameFld;
    private javax.swing.JLabel mNameLbl;
    private javax.swing.JFormattedTextField passportFld;
    private javax.swing.JLabel passportLbl;
    private javax.swing.JFormattedTextField phone1Fld;
    private javax.swing.JLabel phone1Lbl;
    private javax.swing.JFormattedTextField phone2Fld;
    private javax.swing.JLabel phone2Lbl;
    private javax.swing.JComboBox prefixBox;
    private javax.swing.JButton saveBtn;
    private javax.swing.JTextField stateFld;
    private javax.swing.JLabel stateLbl;
    private javax.swing.JTextField streetNameFld;
    private javax.swing.JLabel streetNameLbl;
    private javax.swing.JTextField streetNoFld;
    private javax.swing.JLabel streetNoLbl;
    private javax.swing.JFormattedTextField zipFld;
    private javax.swing.JLabel zipLbl;
    // End of variables declaration//GEN-END:variables
}
